package sys.knot.service;

import org.slf4j.Logger;
import sys.knot.configuration.ApplicationConfiguration;
import sys.knot.configuration.ServiceConfiguration;
import sys.knot.data.access.QueryRunner;
import sys.knot.model.Indata;
import sys.knot.model.ResultConsumer;
import sys.knot.validator.ValidationException;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@RequestScoped
public class QueryService {

    @Inject
    ApplicationConfiguration applicationConfiguration;
    @Inject
    QueryRunner queryRunner;
    @Inject
    Logger logger;

    public void run(Indata indata, ResultConsumer resultConsumer) {
        logger.info("Someone called url: " + indata.getServiceEndPoint());

        ServiceConfiguration serviceConfiguration = applicationConfiguration.
                getServiceConfiguration(indata.getServiceMethod(), indata.getServiceEndPoint());

        queryRunner.runQuery(serviceConfiguration, indata, resultConsumer);
    }
}
